package com.trainingcloud.action.user;

import java.util.Vector;

import org.dom4j.Element;

import com.trainingcloud.XMLSerializer;
import com.trainingcloud.action.BaseSessionAction;
import com.trainingcloud.dao.UserDAO;
import com.trainingcloud.entity.User;
import com.trainingcloud.exception.DAOException;
import com.trainingcloud.exception.SystemException;

public class ListUserAction extends BaseSessionAction
{
	public ListUserAction() throws SystemException 
	{
		super();
	}

	@Override
	public String callWithSession() throws DAOException, SystemException 
	{
		if(!currentUser.getRole().isUserManagement())
		{
			return "No access";
		}
		UserDAO userDAO = new UserDAO();
		Vector<User> userList = userDAO.getAllUsers();
		
		Element listElement = responseElement.addElement("userList");
		for(int i=1; i<=userList.size(); i++)
		{
			XMLSerializer.userToXML(userList.get(i-1), listElement);
		}
		return null;
	}

}
